//
//  MPCardViewController.m
//  sanguosha
//
//  Created by caiqilin on 2017/6/30.
//  Copyright © 2017年 caiqilin. All rights reserved.
//

#import "MPCardViewController.h"
#import "MPCardTypeViewCell.h"
#import "MPCardDetailViewController.h"
#import "CategoryMeunModel.h"
#import "MPCard.h"
#import "MJExtension.h"
@interface MPCardViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray * _list;
}
@property (strong , nonatomic) UITableView *table;
@property(assign,nonatomic,readonly) NSInteger selectIndex;
@property (nonatomic, strong) NSMutableArray * cardArr;

@end

@implementation MPCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"卡牌";
    
    [self initView];
    
    //初始化数据
    [self initData];
}
- (void)initData{
    
    _list=[NSMutableArray arrayWithCapacity:0];
    _cardArr=[NSMutableArray arrayWithCapacity:0];
    
    
    NSString *path=[[NSBundle mainBundle] pathForResource:@"CardCategory" ofType:@"plist"];
    NSArray *array=[NSArray arrayWithContentsOfFile:path];
    /**
     *  构建需要数据 2层或者3层数据 (ps 2层也当作3层来处理)
     */
    
    for (int i=0; i<[array count]; i++) {
        
        CategoryMeunModel * meun=[[CategoryMeunModel alloc] init];
        meun.menuImage=[array objectAtIndex:i][@"menuImage"];
        meun.nextArray=[array objectAtIndex:i][@"topMenu"];
        [_cardArr addObject:meun.nextArray];
        [_list addObject:meun];
    }
    [self.table reloadData];
}


- (void)initView {
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT-20) style:UITableViewStyleGrouped];
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.showsVerticalScrollIndicator = false;
    [self.table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.table.backgroundColor = [Util stringTOColor:@"#f2f2f2"];
    [self.view addSubview:self.table];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _list.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MPCardTypeViewCell *orderManageCell = [MPCardTypeViewCell cellWithTableView:tableView];
    CategoryMeunModel * menu=_list[indexPath.row];
    orderManageCell.typeImageView.image = [UIImage imageNamed:menu.menuImage];
    
    return orderManageCell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 200;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    MPCardDetailViewController *recommend = [[MPCardDetailViewController alloc] init];
    recommend.index = indexPath.row;
    [self.navigationController pushViewController:recommend animated:YES];
}

@end

